<?php
require "sys_basic.php";
/* 2019-7-21 1:55 PM 测试完成 没有问题*/
function game_set($index,$guid) {
   setcookie("userid",$guid,time()+3600*24*265);
   $key=encrypt((string)$index,$guid);
   setcookie("userkey",$key,time()+3600*24*265);
   return  $key;
   }
function game_get($key,$guid){
	//echo decrypt($key,$guid);
	return (int)decrypt($key,$guid);
}
function game_down($key,$guid){
	if((int)game_get($key,$guid)>0)
	{
	    header("Content-type:application/octet-stream");
	    header("Accept-Ranges:bytes");
     	header("Accept-Length:".strlen($key." ".$guid));
    	header("Content-Disposition: attachment; filename=hackgame.key");	
		echo $key." ".$guid;
		exit;
	}else{
		echo "解析错误";
	}
	
}
function game_load($file){
	$filearry=explode(" ",$file);
	if(count($filearry)==2){
		if(game_get($filearry[0],$filearry[1])>0)
		{
			setcookie("userkey",$filearry[0],time()+3600*24*265);
			setcookie("userid",$filearry[1],time()+3600*24*265);
		}
	}
}
function game_check($key,$guid,$index){
	// echo $index;
	// echo '<br>'.game_get($key,$guid);
	if((int)game_get($key,$guid)>=(int)$index and (int)$index>=0){
		return true;
	}
	return false;
}
